/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package control

import dao.EmailsDAO
import entity.Email
import java.sql.Connection
/**
 *
 * @author Tato
 */
class ControlEmail {
    
     EmailsDAO dao = new EmailsDAO()
   
    def addEmail(Email email){
        
        key = dao.create(email,DBConnection.establishConection())
        if(key > 0){
            email.id= key 
            "Email agregado"
        }
        else{
            "Email no agregado"
        }
    }
    
    def deleteEmail(Email email){
        
        
        delete = dao.remove(email,DBConnection.establishConection())
        
        if(delete == true){
            "Borrado exitoso"
        }
        else{
            "Borrado falló"
        }     
    }
    
    def updateEmail(Email email){
        
        if(dao.update(email,DBConnection.establishConection()) > 0){
               "Información actualizada"
            }
            
            else {
                "Información no actualizada"
            }
        
    }
    
     def findEmail(Integer id){
         
        if(dao.find(id,DBConnection.establishConection())!= null  ){
               "Información actualizada"
            }
            
            else {
                "Información no actualizada"
            }
        
    }
	
}
